package com.glory.wxelectricitypda.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.wxelectricitypda.R;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;

import java.util.List;

public class AddCarrierDataAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    private FragmentManager fragmentManager;

    public AddCarrierDataAdapter(@Nullable List<String> data, FragmentManager fragmentManager) {
        super(R.layout.item_add_carrier_data,data);
        this.fragmentManager = fragmentManager;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        helper.setText(R.id.tvPosition,String.valueOf(helper.getAdapterPosition() + 1));
        helper.setText(R.id.tvCarrierID,String.valueOf(item));
        helper.getView(R.id.ivDelete).setOnClickListener(view -> {

            FreeApi_DialogUtils.getConfirmAndCancelDialog(mContext, "是否确认删除?", new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    remove(helper.getAdapterPosition());
                    notifyDataSetChanged();
                }
            }, () -> {}).show(fragmentManager,"DELETE_DIALOG");
        });
    }

}
